package ch.pizzapp.kurier.view;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import ch.pizzapp.kurier.Constants;
import ch.pizzapp.kurier.R;
import ch.pizzapp.kurier.data.NotificationData;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;

/**
 * Shanuka @Cyberlmj 3:08:30 PM Email: shanuka.gayashan@cyberlmj.com
 */
@EViewGroup(R.layout.notification_item)
public class NotificationItem extends RelativeLayout {

	@ViewById(R.id.forum_title)
	TextView forumTitle;

	@ViewById(R.id.forum_date)
	TextView forumDate;

	@ViewById(R.id.imageViewIcon)
	ImageView imageViewIcon;

	private DisplayImageOptions options;
	private ImageLoader imageLoader;

	public NotificationItem(final Context context) {
		super(context);

	}

	@AfterViews
	void initAdapter() {
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.white_background)
				.showImageForEmptyUri(R.drawable.white_background)
				.showImageOnFail(R.drawable.white_background)
				.cacheInMemory(true).cacheOnDisc(true)
				.displayer(new SimpleBitmapDisplayer()).build();
		imageLoader = ImageLoader.getInstance();
	}

	public NotificationItem(final Context context, final AttributeSet attrs) {
		super(context, attrs);
	}

	public void bind(final NotificationData notificationData) {
		forumTitle.setText(notificationData.getMessage());
		forumDate.setText(notificationData.getDate());

		if (notificationData.getImage() != null) {

			imageLoader.displayImage(
					Constants.IMAGE_URL + notificationData.getImage(),
					imageViewIcon, options);
		}
	}
}
